package workclient

import (
	"goruntimeDistributionCrawler/engine"
	"goruntimeDistributionCrawler/rpcsuport"
	"goruntimeDistributionCrawler/workderservice"
	"net/rpc"
)

func Workclient(workChan chan *rpc.Client) engine.WorkerManger {
   return func(r engine.Request) (engine.ParseResult, error) {
	   client:=<-workChan
	    request:=workderservice.SerializeRequst(r)
	    var result workderservice.ParseResult
	   //发起服务
	   err:=client.Call("CrawlService.Process",request,&result)
	   if err!=nil{
	   	  return engine.ParseResult{},err
	   }
	   return workderservice.DeserializeResult(result),nil
   }
}

func CreateClient(host string) (*rpc.Client,error) {

	client,err:=rpcsuport.NewClient(host)
	return client,err
}
